Rsyslog is a rocket-fast system for log processing.
大部分的Linux都預設載入rsyslog用於高效處理日誌
情境: 想要將一台Linux的Web AP Log傳到 SIEM監控,但是該主機不能額外安裝任何程式
conf設定好後重啟 systemctl restart rsyslog.service
vi /etc/rsyslog.conf
# 載入imfile讀取文檔模組,設定每 10 秒檢查一次
module(load="imfile" PollingInterval="10")
input(type="imfile"
# 要監控的Log路徑
File="/ap/logs/WebApp.log"
# 設定標籤
Tag="ap-log"
Severity="debug"
# 設定為debug Level
Facility="local7")
# 定義遠端日誌伺服器
# 選擇使用 TCP 協定將所有日誌發送到遠端伺服器
*.* @@172.17.1.1:514
# 選擇使用 UDP 協定只傳送debug Log,但不包括mail及news日誌發送到遠端伺服器
#*.debug;mail.none;news.none @172.17.1.1
RSYSLOG 支援許多module
https://www.rsyslog.com/doc/configuration/modules/idx_input.html.
imdocker: Docker Input Module
imfile: Text File Input Module
imhttp: http input module
imkafka: read from Apache Kafka
imklog: Kernel Log Input Module
...
Security
https://www.rsyslog.com/doc/configuration/filters.html
分成7類 debug, info, notice, warning, crit, alert, emerg
Facility values
RFC定義分成0 to 23,local use為自行定義,()內為建議分類
https://datatracker.ietf.org/doc/html/rfc5424
Numerical Facility
Code
0 kernel messages
1 user-level messages
2 mail system
3 system daemons
4 security/authorization messages
5 messages generated internally by syslogd
6 line printer subsystem
7 network news subsystem
8 UUCP subsystem
9 clock daemon
10 security/authorization messages
11 FTP daemon
12 NTP subsystem
13 log audit
14 log alert
15 clock daemon (note 2)
16 local use 0 (Emergency: system is unusable)
17 local use 1 (Alert: action must be taken immediately)
18 local use 2 (Critical: critical conditions)
19 local use 3 (Error: error conditions)
20 local use 4 (Warning: warning conditions)
21 local use 5 (Notice: normal but significant condition)
22 local use 6 (Informational: informational messages)
23 local use 7 (Debug: debug-level messages)
sysklogd format
https://www.rsyslog.com/doc/configuration/examples.html
https://www.rsyslog.com/doc/configuration/sysklogd_format.html
SELECTORS
[facility].[severity]
第一個 * 代表所有的設施(facility),第二個 * 代表所有的嚴重程度(severity)
訊息轉送到遠端主機,@@是TCP,@是UDP
轉送到其他logmail.none /var/log/messages
# 載入 UDP 模組
module(load="imudp")
# 設定 UDP 端口 514 來接收訊息
input(type="imudp" port="514")
# 載入 TCP 模組
module(load="imtcp")
# 設定 TCP 端口 514 來接收訊息
input(type="imtcp" port="514")
# 定義訊息輸出的目的地,這裡設定為 /var/log/remote-incoming-logs.log
action(type="omfile" file="/var/log/remote-incoming-logs.log")
# 將所有接收到的訊息寫入定義的目的地
*.* /var/log/remote-incoming-logs.log
# 丟棄所有已經寫入目的地的訊息
& ~
https://www.rsyslog.com/doc/index.html
https://en.wikipedia.org/wiki/Syslog
https://medium.com/pizzas/rsyslog%E4%BB%8B%E7%B4%B9%E8%88%87%E4%BD%BF%E7%94%A8-cfb36497092d